import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/index'
  },
  {
    path: '/index',
    name: 'index',
    component: () => import('@/view/index'),
    meta: {
      title: '首页'
    },
  },
/*   {
    path: '/',
    name: '',
    component: () => import('@/view/xxx'),
    meta: {
      title: ''
    },
  }, */

/*     {
      path: '/',
      name: '',
      component: () => import( '@/view/xxx'),
      children:[
        {
          path: '/',
          redirect: 'home'
        }
      ]
    }, */
]
function VueRouter2(options) {
    if (options.routes) {
      let arr = options.routes
      for (let k in arr) {
        if (arr[k].path && arr[k].component && !arr[k].beforeEnter) {
          arr[k].beforeEnter = (to, from, next) => {
            console.log("beforeEnter  "+arr[k].path);
            next();
          }
        }
      }
    }
    VueRouter.call(this, options);
    // console.log("uuui",this.beforeEach)
    this.beforeEach((to, from, next) => {
      console.log("beforeEach   "+to.path)
      next();
    })
    this.afterEach((to, from) => {
      console.log("afterEach  "+to.path)
    });
    this.beforeResolve((to, from, next) => {
      console.log("beforeResolve   "+to.path)
      next();
    })
  }
  VueRouter2.prototype=VueRouter.prototype;
  VueRouter2.prototype.constructor=VueRouter;

const router = new VueRouter2({
  routes
})

export default router
